import { createRouter, createWebHistory } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

NProgress.configure({ showSpinner: false })

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', redirect: '/login' },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login.vue'),
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('@/views/Home.vue'),
    },
    {
      path: '/admin',
      component: () => import('@/layouts/AdminLayout.vue'),
      children: [
        { path: '', redirect: '/admin/dashboard' },
        {
          path: 'dashboard',
          name: 'admin-dashboard',
          component: () => import('@/views/admin/Dashboard.vue'),
        },
        {
          path: 'cinema',
          name: 'admin-cinema',
          component: () => import('@/views/admin/Cinema.vue'),
        },
        {
          path: 'seat',
          name: 'admin-seat',
          component: () => import('@/views/admin/Seat.vue'),
        },
        {
          path: 'movies',
          name: 'admin-movies',
          component: () => import('@/views/admin/Movies.vue'),
        },
        {
          path: 'ticket',
          name: 'admin-ticket',
          component: () => import('@/views/admin/Ticket.vue'),
        },
        {
          path: 'user',
          name: 'admin-user',
          component: () => import('@/views/admin/User.vue'),
        },
        {
          path: 'comment',
          name: 'admin-comment',
          component: () => import('@/views/admin/Comment.vue'),
        },
        {
          path: 'save',
          name: 'admin-save',
          component: () => import('@/views/admin/Save.vue'),
        },
      ],
    },
  ],
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  next()
})

router.afterEach(() => {
  NProgress.done()
})

export default router
